
import 'package:flutter/material.dart';
import 'package:reabammendian/src/reabam/operation/rb_config.dart';
import 'package:reabammendian/src/reabam/operation/rb_enum.dart';
import 'package:reabammendian/src/reabam/ui/pagestate_main_webview.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';
import 'package:xsdk_flutter_plugin/xsdk_flutter_plugin.dart';

/*
欢迎页
hyl 2022.12.28
 */
class WelcomeStatePage extends XPageWelcomeState{
  WelcomeStatePage({required super.milliseconds});


  @override
  void onStart() {
    XFlutterUtils.setScreenOrientation(false);
    super.onStart();

    XFlutterUtils.setSystemStatusBar(false);
    //保持设备唤醒状态
    XFlutterUtils.keepWakelock();

    //获得权限
    XPermissionUtils.requestAllPermissions();

    // //初始化socket设备
    // XSocketUtils.init();
    // //初始化蓝牙设备
    // XBluetoothBLEUtils.init();
    // //初始化阿里云日志
    // _initAliyunLog();
    // //初始化android设备(商米机等)
    // _initAndroid();
    //
    // //文字转语音
    // XTTSUtils.initTts();

  }

  //初始化android设备(商米机等)
  void _initAndroid() async{
    String systemName=XFlutterUtils.getSystemName();
    if('Android'==systemName){
      Map<String, dynamic> deviceInfo= await XDeviceUtils.getDeviceInfo();
      XLogUtils.printLog('---Android deviceInfo= $deviceInfo');
      dynamic brand=  deviceInfo['brand'];
      //
      if(XStringUtils.equalsIgnoreCase('SUNMI', brand)){
        //初始化商米机
        XLogUtils.printLog('---初始化商米机');
        RBConfigs.isShangMiPrinter=true;
        XFlutterPluginUtils.initShangMiSDK();
      }

    }
  }


  //初始化阿里云日志
  void _initAliyunLog(){

    String endpoint;
    String project;
    String logstore;
    String accesskeyid;
    String accesskeysecret;

    if(RBConfigs.versionType==VersionType.officialVersion){
      //正式版
      endpoint='https://cn-shenzhen.log.aliyuncs.com';
      project='reabam-app-log';
      logstore='pos_app_android_prod';
      accesskeyid='LTAI5t6gtXxdKepYHRymyFTX';
      accesskeysecret='wwrc7roPwIlAzYGMLSNfhhDn7nkyWL';

    }else{
      //测试版
      endpoint='https://cn-shenzhen.log.aliyuncs.com';
      project='reabam-app-log';
      logstore='pos_app_android_test';
      accesskeyid='LTAI5t6gtXxdKepYHRymyFTX';
      accesskeysecret='wwrc7roPwIlAzYGMLSNfhhDn7nkyWL';
    }

    XAliyunUtils.init(
        appName: '收银端Flutter, version= ${RBConfigs.version}',
        endpoint: endpoint,
        project: project,
        logstore: logstore,
        accessKeyID: accesskeyid,
        accessKeySecret: accesskeysecret
    );
  }


  @override
  Widget getBodyWidget(BuildContext context) {
    return XWidgetUtils.getLayoutCenter(XImageUtils.getImageWidgetWithAsset(
        'welcome_app.png',
        width: 122,
        height: 32.5
    ),
    );
  }

  @override
  void goNextPage() {
    startPage(MainWebViewStatePage(),isFinish: true);
    //startPage(SettingStatePage(),isFinish: true);

    //startPage(TestAndroidStatePage(),isFinish: true);
    //startPage(TestRealmStatePage(),isFinish: true);
    //startPage(TestClientSocketStatePage(),isFinish: true);
  }


}